#include "centralcontrolform.h"
#include "ui_centralcontrolform.h"
#include "qqtcore.h"
#include "qqtclickwidget.h"
#include "framecore.h"
#include <qqtframe.h>

CentralControlForm::CentralControlForm ( QWidget* parent ) :
    HuanFrame ( parent ),
    ui ( new Ui::CentralControlForm )
{
    ui->setupUi ( this );
    setFixedSize ( 400, 400 );
    pline() << this->geometry();
    initControl();
    initSiri();
}

CentralControlForm::~CentralControlForm()
{
    delete ui;
}

void CentralControlForm::initControl()
{
    ui->w01->setText ( "SELECT" );
    ui->w02->setText ( "CONTROL" );
    ui->w03->setText ( "SETUP" );
    ui->w04->setText ( "SCENES" );

    HuanButton* w[4] = {0};

    w[0] = ui->w01;
    w[1] = ui->w02;
    w[2] = ui->w03;
    w[3] = ui->w04;

    //pline() << this->width() << this->height();
    for ( int i = 0; i < 4; i++ )
    {
        w[i]->setGeometry ( calculatePosition ( this, i,
                                                this->width() / 2 - 40 - 5,
                                                40,
                                                4 ) );
        pline() << "control" << i << w[i]->geometry();
        w[i]->setIcon ( skin ( "demo/icon_default.png" ) );

    }

    connect ( ui->w01, SIGNAL ( click() ),
              this, SLOT ( clicked() ) );
    connect ( ui->w02, SIGNAL ( click() ),
              this, SLOT ( clicked() ) );
    connect ( ui->w03, SIGNAL ( click() ),
              this, SLOT ( clicked() ) );
    connect ( ui->w04, SIGNAL ( click() ),
              this, SLOT ( clicked() ) );
}

void CentralControlForm::initSiri()
{
    QWidget* w[4] = {0};

    w[0] = ui->w11;
    w[1] = ui->w12;
    w[2] = ui->w13;
    w[3] = ui->w14;

    for ( int i = 0; i < 4; i++ )
    {
        w[i]->setGeometry ( calculatePosition ( this, i,
                                                this->width() / 2 - 30 - 5 - 100,
                                                20,
                                                4 ) );
        pline() << "siri" << i << w[i]->geometry();
        w[i]->hide();
    }
}

void CentralControlForm::clicked()
{
    QObject* obj = sender();

    //select
    if ( obj == ui->w01 )
        emit currentIndexChanged ( 0 );
    //control
    else if ( obj == ui->w02 )
        emit currentIndexChanged ( 2 );
    //setup
    else if ( obj == ui->w03 )
        emit currentIndexChanged ( 3 );
    //scene
    else if ( obj == ui->w04 )
        emit currentIndexChanged ( 1 );
}
